<template>
  <view class="climber-mine">
    <!-- 头部标题 -->
    <view class="header">
      <text class="title">陪跑员接单</text>
    </view>

    <!-- 个人信息卡片 -->
    <view class="profile-card">
      <image class="avatar" :src="avatar || '/static/project/2025-10-14_110352_756.png'" mode="aspectFill" />
      <view class="verified-badge">
        <text class="badge-icon">✓</text>
      </view>
      <text class="name">{{ name || '张教练' }}</text>
      <text class="level">高级陪爬教练 • 已认证</text>

      <!-- 统计信息 -->
      <view class="stats">
        <view class="stat-item">
          <text class="stat-value">{{ stats.rating }}</text>
          <text class="stat-label">评分</text>
        </view>
        <view class="stat-item">
          <text class="stat-value">{{ stats.orders }}</text>
          <text class="stat-label">完成订单</text>
        </view>
        <view class="stat-item">
          <text class="stat-value">{{ stats.satisfaction }}%</text>
          <text class="stat-label">好评率</text>
        </view>
      </view>

      <!-- 编辑资料按钮 -->
      <button class="btn-edit" @tap="editProfile">
        <text class="icon">📝</text>
        编辑资料
      </button>
    </view>

    <!-- 收入统计 -->
    <view class="income-section">
      <view class="income-header">
        <text class="income-icon">💰</text>
        <text class="income-label">累计收入</text>
        <text class="income-more" @tap="goToIncome">›</text>
      </view>
      <view class="income-value">
        <text class="currency">¥</text>
        <text class="amount">{{ income.total }}</text>
      </view>
      <text class="income-desc">已开发服务 {{ income.count }}/00</text>
    </view>

    <!-- 功能菜单 -->
    <view class="menu-section">
      <text class="section-title">功能菜单</text>

      <view class="menu-item" @tap="goToMyOrders">
        <view class="menu-left">
          <text class="menu-icon">📋</text>
          <text class="menu-text">我的订单</text>
        </view>
        <view class="menu-right">
          <text class="menu-desc">查看所有订单记录</text>
          <text class="arrow">›</text>
        </view>
      </view>

      <view class="menu-item" @tap="goToIncomeMgmt">
        <view class="menu-left">
          <text class="menu-icon">💵</text>
          <text class="menu-text">收入管理</text>
        </view>
        <view class="menu-right">
          <text class="menu-desc">查看收入明细及提现</text>
          <text class="arrow">›</text>
        </view>
      </view>

      <view class="menu-item" @tap="goToRating">
        <view class="menu-left">
          <text class="menu-icon">⭐</text>
          <text class="menu-text">服务评价</text>
        </view>
        <view class="menu-right">
          <text class="menu-desc">查看所有用户评价</text>
          <text class="arrow">›</text>
        </view>
      </view>

      <view class="menu-item" @tap="goToCert">
        <view class="menu-left">
          <text class="menu-icon">🎓</text>
          <text class="menu-text">资质认证</text>
        </view>
        <view class="menu-right">
          <text class="menu-desc">查看与更新资质证书</text>
          <text class="arrow">›</text>
        </view>
      </view>

      <view class="menu-item" @tap="goToSetting">
        <view class="menu-left">
          <text class="menu-icon">⚙️</text>
          <text class="menu-text">应用设置</text>
        </view>
        <view class="menu-right">
          <text class="menu-desc">修改密码、检查更新等</text>
          <text class="arrow">›</text>
        </view>
      </view>
    </view>

    <!-- 退出登录 -->
    <view class="logout-section">
      <button class="logout-btn" @tap="handleLogout">退出登录</button>
    </view>

    <!-- 底部占位 -->
    <view class="tabbar-placeholder"></view>
    
    <!-- Tabbar -->
    <climber-tabbar :active="2" />
  </view>
</template>

<script>
import { mapGetters } from 'vuex'
import ClimberTabbar from '@/components/climber-tabbar/climber-tabbar.vue'

export default {
  components: { ClimberTabbar },
  data() {
    return {
      stats: {
        rating: 4.9,
        orders: 128,
        satisfaction: 98
      },
      income: {
        total: '32,450',
        count: 128
      }
    }
  },
  computed: {
    ...mapGetters(['name', 'avatar'])
  },
  onLoad() {
    this.loadProfile()
  },
  methods: {
    async loadProfile() {
      // TODO: 调用接口获取配爬员信息
    },
    editProfile() {
      uni.navigateTo({ url: '/pages/climber/edit' })
    },
    goToIncome() {
      this.$modal.showToast('收入详情功能开发中')
    },
    goToMyOrders() {
      uni.navigateTo({ url: '/pages/climber/orders' })
    },
    goToIncomeMgmt() {
      this.$modal.showToast('收入管理功能开发中')
    },
    goToRating() {
      this.$modal.showToast('服务评价功能开发中')
    },
    goToCert() {
      uni.navigateTo({ url: '/pages/climber/register' })
    },
    goToSetting() {
      uni.navigateTo({ url: '/pages/climber/setting/index' })
    },
    handleLogout() {
      uni.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            this.$store.dispatch('LogOut').then(() => {
              this.$tab.reLaunch('/pages/login')
            })
          }
        }
      })
    }
  }
}
</script>

<style scoped>
.climber-mine {
  min-height: 100vh;
  background: #f5f6f7;
}

/* 头部 */
.header {
  background: #fff;
  padding: 32rpx;
  text-align: center;
}

.title {
  font-size: 36rpx;
  font-weight: 700;
  color: #333;
}

/* 个人信息卡片 */
.profile-card {
  background: #fff;
  margin: 20rpx 32rpx;
  border-radius: 24rpx;
  padding: 40rpx 32rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.avatar {
  width: 160rpx;
  height: 160rpx;
  border-radius: 50%;
  border: 6rpx solid #f0f0f0;
  margin-bottom: 20rpx;
}

.verified-badge {
  position: absolute;
  top: 40rpx;
  right: calc(50% - 60rpx);
  width: 40rpx;
  height: 40rpx;
  background: #1989fa;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-icon {
  color: #fff;
  font-size: 24rpx;
  font-weight: 700;
}

.name {
  font-size: 36rpx;
  font-weight: 700;
  color: #333;
  margin-bottom: 12rpx;
}

.level {
  font-size: 24rpx;
  color: #999;
  margin-bottom: 32rpx;
}

/* 统计信息 */
.stats {
  display: flex;
  width: 100%;
  justify-content: space-around;
  margin-bottom: 32rpx;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 40rpx;
  font-weight: 700;
  color: #1989fa;
  margin-bottom: 8rpx;
}

.stat-label {
  font-size: 24rpx;
  color: #999;
}

/* 编辑资料按钮 */
.btn-edit {
  width: 100%;
  height: 80rpx;
  background: #f5f8ff;
  border: none;
  border-radius: 16rpx;
  color: #1989fa;
  font-size: 28rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-edit .icon {
  margin-right: 8rpx;
}

/* 收入统计 */
.income-section {
  background: #fff;
  margin: 20rpx 32rpx;
  border-radius: 16rpx;
  padding: 32rpx;
}

.income-header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}

.income-icon {
  font-size: 40rpx;
  margin-right: 12rpx;
}

.income-label {
  flex: 1;
  font-size: 28rpx;
  color: #333;
  font-weight: 600;
}

.income-more {
  font-size: 40rpx;
  color: #ccc;
}

.income-value {
  display: flex;
  align-items: baseline;
  margin-bottom: 12rpx;
}

.currency {
  font-size: 32rpx;
  color: #ff6b00;
  margin-right: 8rpx;
}

.amount {
  font-size: 56rpx;
  font-weight: 700;
  color: #ff6b00;
}

.income-desc {
  font-size: 24rpx;
  color: #999;
}

/* 功能菜单 */
.menu-section {
  background: #fff;
  margin: 20rpx 32rpx;
  border-radius: 16rpx;
  padding: 24rpx;
}

.section-title {
  font-size: 32rpx;
  font-weight: 700;
  color: #333;
  display: block;
  margin-bottom: 24rpx;
}

.menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx 0;
  border-bottom: 1rpx solid #f0f0f0;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-left {
  display: flex;
  align-items: center;
}

.menu-icon {
  font-size: 40rpx;
  margin-right: 16rpx;
}

.menu-text {
  font-size: 28rpx;
  color: #333;
  font-weight: 600;
}

.menu-right {
  display: flex;
  align-items: center;
}

.menu-desc {
  font-size: 24rpx;
  color: #999;
  margin-right: 8rpx;
}

.arrow {
  font-size: 40rpx;
  color: #ccc;
}

/* 退出登录 */
.logout-section {
  padding: 0 32rpx;
  margin-top: 40rpx;
}

.logout-btn {
  width: 100%;
  height: 88rpx;
  background: #fff;
  border: 1rpx solid #ddd;
  border-radius: 16rpx;
  font-size: 28rpx;
  color: #f44336;
}

/* 底部占位 */
.tabbar-placeholder {
  height: 120rpx;
}
</style>

